package com.team5101.controller;

import com.team5101.entity.Resume;
import com.team5101.repository.ResumeRepository;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/resume")
public class ResumeController {

    @Resource
    private ResumeRepository resumeDao;

    @CrossOrigin
    @RequestMapping("/list")
    public List<Resume> list(Model model) {
        List<Resume> result=resumeDao.findAll();
//        HashMap resultmap=new HashMap();
//        resultmap.put("data",result);
        model.addAttribute("data",result);
        return result;
    }

    @CrossOrigin
    @RequestMapping("/add")
    public String add(@RequestBody Resume r) {
        System.out.println(r.toString());
        resumeDao.save(r);
        return "result";
    }

    @CrossOrigin
    @RequestMapping("/edit")
    public String edit(@RequestBody Resume r ){
        System.out.println(r.toString());
        resumeDao.save(r);
        return "result";
    }

    @CrossOrigin
    @RequestMapping("/delete")
    public String delete(@RequestBody Resume r) {
        System.out.println(r.toString());
        resumeDao.deleteById(r.getId());
        return "result";
    }

}
